import { computed, defineComponent, onMounted, onUnmounted, reactive, Ref, ref, toRaw, nextTick } from 'vue';
import { ButtonGroup, Button, notification } from 'ant-design-vue';
import { Download, ReqParam, ResData } from '../types/downLoad';

import { getDownLoadData, deleteDownload } from '../api/download/index';
import { usePageList, apiType } from '@/domain/common/hooks/pageList';
import { Column, ResSearch } from '@/domain/common/types/page';
import { DownLoadId, Workercode } from '../types/common';
import { useUserInfoStore } from '@/domain/authority/hooks/login';

export const useDownloadData = () => {
  const searchRef: Ref<ResSearch> = ref([]);
  const api: apiType<Download, ReqParam> = {
    list: getDownLoadData,
    search: searchRef.value
  };
  const userStore = useUserInfoStore();

  const {
    IDString,
    rowlist,
    columnlist,
    selectRows,
    paging,
    searchParam,
    searchList,
    setSizeChange,
    loadTable,
    getSelectRowsCallBack,
    reloadList,
    getResData
  } = usePageList<DownLoadId, Download, ReqParam>(api, 'id');

  const dataSource = computed(() => rowlist.value.map((node) => Object.assign(node.row, { opGroup: node.op_group })));

  onMounted(async () => {
    //添加字典
    searchList.value = api.search;
    nextTick(async () => {
      await reloadList();
    });
  });
  return {
    IDString,
    dataSource,
    rowlist,
    paging,
    selectRows,
    searchParam,
    columnlist,
    searchList,
    setSizeChange,
    loadTable,
    getSelectRowsCallBack,
    reloadList
  };
};
